package com.atguigu.webadmin.controller.apartment;


import com.atguigu.common.result.Result;
import com.atguigu.webadmin.service.FileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@Tag(name = "文件管理")
@RequestMapping("/admin/file")
@RestController
@CrossOrigin
public class FileUploadController {

    @Autowired
    private FileService fileService;

    @Operation(summary = "上传文件")
    @Parameters({
            @Parameter(name = "file",description = "前端上传的文件",in = ParameterIn.DEFAULT)
    })
    @PostMapping("upload")
    public Result<String> upload(@RequestParam MultipartFile file) {
        //上传文件
        String url = fileService.upload(file);
        return Result.ok(url);
    }

}
